package com.sunwayworld.basemodule.basedata.operationrecord.service.impl;

import com.sunwayworld.basemodule.basedata.operationrecord.bean.LimsOperationrecordBean;
import com.sunwayworld.basemodule.basedata.operationrecord.dao.LimsOperationrecordDao;
import com.sunwayworld.basemodule.basedata.operationrecord.service.LimsOperationrecordService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@GikamBean
public class LimsOperationrecordServiceImpl implements LimsOperationrecordService {

    @Autowired
    private LimsOperationrecordDao limsOperationrecordDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsOperationrecordDao getDao() {
        return limsOperationrecordDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsOperationrecordBean limsOperationrecord = jsonWrapper.parseUnique(LimsOperationrecordBean.class);
        limsOperationrecord.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsOperationrecord);
        return limsOperationrecord.getId();
    }

}
